const { Router } = require('express')
const express = require('express')
const qs = require('querystring')
//路由容器
const search = express.Router()
const axios = require('axios')
const { start } = require('repl')

//搜索内容
search.get('/getAllLikeHome', (req, res) => {
    let {content, setting} = req.query
    
    content = decodeURIComponent(content)
    setting = decodeURIComponent(setting)
    console.log(content,setting);
    axios({
        url:'http://www.mianded.top:8081/goods/getAllLikeHome',
        method:'GET',
        params:{
            content:content,
            setting: setting
        },
        headers:{
            token:req.session.token?req.session.token:"",
        }
    })
    .then(data => {
        console.log(content);
        console.log(data.data);
        res.status(200).json({
            data:data.data
        })
    })
    .catch(err => {
        console.log(err);
        res.status(200).json({
            err:err
        })
    })
    
})

//根据金额查询
search.get('/getGoodsByLimit', (req, res) => {
    const {content, setting, start, end} = req.query
    axios({
        url:'http://www.mianded.top:8081/goods/getGoodsByLimit',
        method:'GET',
        params:{
            content:content,
            setting:setting,
            start:start,
            end:end
        },
        headers:{
            token:req.session.token?req.session.token:"",
        }
    })
    .then(data => {
        console.log(data);
        res.status(200).json({
            data:data.data
        })
    })
    .catch(err => {
        console.log(err);
        res.status(200).json({
            err:err
        })
    })
})

module.exports = search